<?php

class Site_IndexController extends Fengqiaoju_Controller_Action {

	public function init() {

		parent::init ();
		$this->view->site_id = $this->_request->getParam ( 'site_id' );
		$this->view->site_seo_name = $this->_request->getParam ( 'site_seo_name' );
		$this->view->model_id = $this->_request->getParam ( 'model_id' );
		$this->view->model_seo_name = $this->_request->getParam ( 'model_seo_name' );
		$this->view->article_id = $this->_request->getParam ( 'article_id' );
	}

	public function indexAction() {

		$modelObject = new Site_Models_Model ();
		$siteObject = new Site_Models_Site ();
		
		if ($this->view->site_id) {
			//头部导航菜单
			$where ['site_id'] = $this->view->site_id;
			$where ['site_seo_name'] = $this->view->site_seo_name;
			$this->view->modelList = $modelObject->getModelList ( $where );
			
			//模块首页显示数据
			$list = array ();
			if (is_array ( $this->view->modelList->toArray () )) {
				foreach ( $this->view->modelList as $key => $model ) {
					if ($model ['show_index']) {
						$where = '';
						$where = 'model_id=' . intval ( $model ['model_id'] );
						$className = "Site_Models_" . ucfirst ( $model ['model_type'] ) . "";
						$indexObject = new $className ();
						$order = $model ['model_type'] . "_id DESC";
						$model ['show_index'] . " ";
						$list [$key] ['data'] = $indexObject->fetchAll ( $where, $order, intval ( $model ['show_index'] ) )->toArray ();
						$list [$key] ['type'] = $model ['model_type'];
						$list [$key] ['modelName'] = $model ['model_name'];
					}
					$keyword .= $model ['model_name'] . ",";
				}
			}
			$this->view->list = $list;
			
			//当前模块信息
			$this->view->modelInfo = $modelObject->getModelInfo ( $this->view->model_id, $this->view->model_seo_name, $this->view->site_seo_name );
			$where = array ();
			$where ['site_id'] = $this->view->site_id;
			$this->view->siteInfo = $siteObject->getSiteInfo ( $where );
			$where = array ();
			$where ['1'] = 1;
			$this->view->siteList = $siteObject->getSiteList ( $where );
			
			$this->view->title = $this->view->siteInfo ['site_name'] . "-" . $this->config ['site'] ['title'];
			$this->view->keywords = $keyword . $this->view->siteInfo ['site_name'];
			$this->view->description = strip_tags ( $this->view->siteInfo ['site_intro'] ) . "," . $this->view->siteInfo ['site_name'] . "的小站";
		}
		else {
			$where = 'category_fid=0';
			$categoryObject = new Site_Models_Category ();
			$categoryFirst = $categoryObject->fetchAll ( $where, 'category_id DESC', 10, 0 )->toArray ();
			foreach ( $categoryFirst as $key => $val ) {
				$where = "category_id=" . intval ( $val ['category_id'] );
				$categoryFirst [$key] = $val;
				$categoryFirst [$key] ['total'] = count ( $siteObject->fetchAll ( $where ) );
				$categoryFirst [$key] ['cate'] = $siteObject->fetchAll ( $where, 'site_id DESC', 10, 0 )->toArray ();
			}
			
			$this->view->categoryFirst = $categoryFirst;
			$this->view->title = "小站-" . $this->config ['site'] ['title'];
			$this->view->keywords = "小站,兴趣小站,个性小站,个人小站,个人群组,兴趣小组";
			$this->view->description = "枫桥居,个性小站欢迎您的加入,这里有成千上万的兴趣小站,总能找到和您兴趣相投的小站和网友的.";
		}
	
	}
}
?>